package cate.game.role.pay;

import cate.common.table.d.GDFunc;
import cate.common.table.pay.PayItemRow;
import cate.game.pay.PayCallback;
import cate.game.role.Role;
import easy.java.practice.errorcode.EcResult;

public class PayCheck {

    public static EcResult<?> allow(PayItemRow pir, Role role) {
        switch (pir.funcId) {
            case GDFunc.PAY_SHOP_SAMPLE:
                return role.getPay().shopSample.allow(pir);
            case GDFunc.GuildFunc.ENVELOP:
                EcResult<?> r = role.getRes().guild.checkGuild();
                if (r.ok()) {
                    return role.getRes()
                            .guild
                            .getGuild()
                            .envelope
                            .sendRedEnveLopeCheck(role, pir.funcSubId);
                } else {
                    return r;
                }
            case GDFunc.FOREVER_CONTRACT:
                return role.getPay().tradeMall.foreverContract.allowPay();
            default:
                PayCallback payCallback = role.getGame().pay.getPayHandler(pir.funcId);
                if (payCallback != null) {
                    return payCallback.allowPay(role, pir);
                }
                return new EcResult<Void>().fail("不支持的充值项功能ID=" + pir.funcId);
        }
    }
}
